using System.Linq;
using TechTalk.SpecFlow;

namespace Baula.TextGen.ActiveTemplating.Specs
{
    public static class SpecFlowExtensions
    {
        public static FormsContext ToFormsContext(this Table table)
        {
            return new FormsContext(
                table.Rows.Select(row => new FormInfo(row["Form.Name"]))
                );
        }

        public static T GetOrDefault<T>(this ScenarioContext context)
            where T : class 
        {
            var key = typeof(T).FullName ?? string.Empty;
            if (context.ContainsKey(key))
            {
                return context.Get<T>();
            }
            return default(T);
        }
    }
}